package com.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 
 * @author Hongten</br>
 * @date 2012-7-16
 * 
 */

public class DBManager {
	static String driver = "com.mysql.jdbc.Driver";
	static String dbName = "smsps";
	static String passwrod = "root";
	static String userName = "root";
	static String url = "jdbc:mysql://localhost:3306/" + dbName;
	static String sql = "select * from smsinfo";

	public static Connection getConn() throws ClassNotFoundException,
			SQLException {
		Class.forName(driver);
		Connection conn = DriverManager.getConnection(url, userName, passwrod);
		return conn;
	}

	public static void close(ResultSet rs, PreparedStatement ps, Connection conn) {
		// 关闭记录集
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		// 关闭声明
		if (ps != null) {
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		// 关闭链接对象
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}